package com.ruoyi.web.controller.grade;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.grade.domain.entity.StudentTotalGrade;
import com.ruoyi.grade.service.IStudentTotalGradeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;
@CrossOrigin
@Api(tags = "学生总成绩模块")
@RestController
@RequestMapping("/student/total_grade")
@PreAuthorize("@ss.hasPermi('student:totalgrade:controller')")
public class StudentTotalGradeController extends BaseController {

    @Autowired
    private IStudentTotalGradeService studentTotalGradeService;

    @ApiOperation(value = "导入学生总成绩(返回插入失败信息)")
    @PostMapping("/import")
    @PreAuthorize("@ss.hasPermi('student:total_grade:import')")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "认证码", paramType = "header", required = true),
            @ApiImplicitParam(name = "updateSupport", value = "是否更新支持，如果已存在，则进行更新数据", required = true)
    })
    public AjaxResult importStudentCourseGrade(@RequestPart MultipartFile file, boolean updateSupport) throws IOException {
        ExcelUtil<StudentTotalGrade> util = new ExcelUtil<StudentTotalGrade>(StudentTotalGrade.class);
        List<StudentTotalGrade> studentTotalGradeList = util.importExcel(file.getInputStream());
        String message = studentTotalGradeService.importUser(studentTotalGradeList, updateSupport);
        return success(message);
    }
}
